<?php
namespace app\index\controller;
use app\index\model\Blog;
use app\index\model\Content;

use app\index\model\Archive as Arc;
use app\index\model\Article as Art;

class Test
{
    public function t1()
    {

		$blog        = new Blog;
		$blog->name  = 'thinkphp';
		$blog->title = 'ThinkPHP5关联实例';
		if ($blog->save()) {
		    $content       = new Content;
		    $content->data = '实例内容';
		    dump($blog->content()->save($content));
		}

    }

    public function t2()
    {
		$data = [
		    'name'  => 'thinkphp',
		    'title' => 'ThinkPHP5关联实例222',
		];
		$blog    = Blog::create($data);
		$content = [
		    'data' => '实例内容',
		];
		dump($blog->content()->save($content));
    }

    public function t3()
    {
    	//错误
		$blog          = new Blog;
		$blog->name    = 'thinkphp';
		$blog->title   = 'ThinkPHP5关联实例333';
		$blog->content = ['data' => '实例内容'];
		dump($blog->together('content')->save());
    }

    public function t4()
    {
    	//错误
    	$blog          = new Blog;
		$blog->name    = 'thinkphp';
		$blog->title   = 'ThinkPHP5关联实例';
		$blog->data 	= 'neirong';
		dump($blog->together(['content'=>'data'])->save());
    }

    public function t5()
    {
    	$blog 		=	new Blog;
    	$blog->name =	'thinkphp~';
    	$blog->title=	'Thinkphp~~~THIS IS php';

    	$content 	=	new Content;
    	$content->data = 'neirong';
    	$blog->content = $content;
    	$blog->together('content')->save();
    }

    public function t6()
    {
		$blog        = Blog::get(2);
		$blog->title = '更改xx标题xxxxxxxx';
		$blog->content->data  = '更新内容xxxxxxxxxxx';

		// 更新当前模型及关联模型
		dump($blog->together(['content'])->save());
    }

    public function t7()
    {
		$blog = new Blog;

		$blog->name = 'test';
		$blog->title = 'cccc';
		$blog->content->data = 'tests';

		// 删除当前及关联模型
		$blog->together('content')->save();
    }

    public function t8()
    {
    	$arc = new Arc;
    	$arc->title = 'test_Title';

    }
}
